# -*- coding: utf-8 -*-
"""
Created on 15-12-16 上午11:31
@file: getcooike.py
@author: Liangrong Li
@contact: liliangrong0@126.com
"""

import urllib2
import cookielib

#声明一个CookieJar对象实例来保存cookie
cookie = cookielib.CookieJar()

#利用urllib2库的HTTPCookieProcessor对象来创建cookie处理器
handler = urllib2.HTTPCookieProcessor(cookie)

#通过handler来构建opener
opener = urllib2.build_opener(handler)

#吃醋的open方法同urllib2的urlopen方法，也可以传入request
resp = opener.open("http://www.baidu.com")

#直接打印出cookie数据
# for item in cookie:
#     print 'Name = ' + item.name
#     print 'Value = ' + item.value

